﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using CMS.Core.Domain;
using ProjectBase.Utils;

namespace CMS.Web.Common
{
    public partial class VBound : ViewUserControl
    {
        public string ViewId;
        public string Title;
        public string TenHamDong = "";
        public bool IsActive = false;
        public List<BaiVietTheLoai> MenuSubs;
        public List<BaiVietTheLoai> AllMenus;
        private bool _isLinkChild = false;
        private string _childId = "";

        protected void Page_Load(object sender, EventArgs e)
        {

            this.IsActive = true;
            LoadMenuSub();
        }

        public void Init_VBound(string ViewId, string TieuDe, bool IsActive, bool IsLinkChild, object ChildId)
        {
            this.ViewId = ViewId;
            this.Title = Server.HtmlEncode(TieuDe);
            this.IsActive = IsActive;
            this._isLinkChild = IsLinkChild;
            this._childId = (null != ChildId) ? ChildId.ToString() : "";
        }
        public void LoadMenuSub()
        {
            SubVBound ctlIB = null;
            foreach (BaiVietTheLoai entity in MenuSubs)
            {
                ctlIB = (CMS.Web.Common.SubVBound)Page.LoadControl("Common/Menu/SubVBound.ascx");
                if (entity.ID.Equals(this.CatId))
                {
                    ctlIB.Init_SubVBound(entity.ID.ToString(), entity.TenTheLoai, true);
                }
                else
                {
                    ctlIB.Init_SubVBound(entity.ID.ToString(), entity.TenTheLoai, false);
                }
                this.ulCat.Controls.Add(ctlIB);
            }
        }       

        public string LinkChild()
        {
            string sLink = "";

            if (_isLinkChild)
            {
                if ("".Equals(_childId))
                    sLink = this.HomeUrl + "?cid=" + ViewId;
                else
                    sLink = this.HomeUrl + "?cid=" + _childId;
            }
            else
            {
                sLink = this.HomeUrl + "?cid=" + ViewId;

            }
            return sLink;
        }
    }
}